package com.frxuexi.park2212.visit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.base.BaseActivity
import com.frxuexi.lib_base.entity.VisitBeanItem
import com.frxuexi.park2212.R
import com.frxuexi.park2212.databinding.ActivityVisitAddBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/VisitAddActivity")
@AndroidEntryPoint
class VisitAddActivity : BaseActivity<ActivityVisitAddBinding, VisitViewModel>() {
    override fun initData() {
        vm.addVisit.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
    }

    override fun initView() {
        binding.headVisitAdd.apply {
            headerBack.setOnClickListener {
                finish()
            }
            headerTitle.setText("添加访客")
            headerAdd.setImageResource(R.drawable.ic_action_ok)
            headerAdd.setOnClickListener {
                val uname = binding.visitaddUser.text.toString()
                val phone = binding.visitaddPhone.text.toString()
                val card = binding.visitaddCard.text.toString()
                val date = binding.visitaddDate.text.toString()
                val start = binding.visitaddStart.text.toString()
                val purpose = binding.visitaddPurpose.text.toString()
                val checked = binding.visitaddSwitch.isChecked
                val carNo = binding.visitaddCarNo.text.toString()
                val emp = binding.visitaddEmp.text.toString().toInt()
                val item = VisitBeanItem(
                    date + " " + start, false, null, emp,
                    null, card, phone, carNo, purpose, checked, "待审核", uname
                )
                vm.addVisit(item)
            }
        }
        binding.visitaddIvdate.setOnClickListener {
            showDateDialog(binding.visitaddDate)
        }

        binding.visitaddIvstart.setOnClickListener {
            showTimeDialog(binding.visitaddStart)
        }

        binding.visitaddIvend.setOnClickListener {
            showTimeDialog(binding.visitaddEnd)
        }

        binding.visitaddSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
            binding.visitaddCarNo.isEnabled=isChecked
        }
    }

}